import java.util.Stack;
//得到栈中的最小值
public class MinStack {
    Stack<Integer> stack;
    Stack<Integer> minStack;
    public MinStack(){
        stack=new Stack<>();
        minStack=new Stack<>();
    }
    public void push(int val){
        stack.push(val);
        if (minStack.isEmpty()){
            minStack.push(val);
        }else {
            Integer peekVal=minStack.peek();
            if (val<=peekVal){
                minStack.push(val);
            }
        }
    }
    public void pop(){
        if(stack.isEmpty()){
            return;
        }
        int popVal=stack.pop();
        if (popVal==minStack.peek()){
            minStack.pop();
        }
    }
    public int top(){
        if (stack.empty()){
            return -1;
        }else {
            return stack.peek();
        }
    }
    public int getMin(){
        if (stack.empty()){
            return -1;
        }else {
            return minStack.peek();
        }
    }

}
